﻿
<%
	var Helpers = {
		
		IsNumeric: function(n) {
			return !isNaN(parseFloat(n)) && isFinite(n);
		},
		
		/*----------------------------------------------------------------------*/
		PropertiesToJavaScript: function(parent, jsObj, properties){
			
			var output = ["<script type='text/javascript'> \n"];
			
			for(var x = 0, len = properties.length; x < len; x++){
				var curProperty = properties[x];
				
				output.push(jsObj + "." + curProperty + " = " + parent[curProperty] + "; \n");	
			}
			
			outputs.push("</script>");
			
			return outputs.join("");
		},
		
		/*----------------------------------------------------------------------*/
		CreateTimeStampDBID: function(){
			var d = new Date();
			var year = (d.getFullYear().toString().substring(2));
			var month = this.PadWithZero(d.getMonth() + 1);
			var day = this.PadWithZero(d.getDate());
			var hour = this.PadWithZero(d.getHours());
			var minute = this.PadWithZero(d.getMinutes());
			var second = this.PadWithZero(d.getSeconds());
			
			
			return year + month + day + hour + minute + second;
		},
		
		/*----------------------------------------------------------------------*/
		PadWithZero: function(value){
			value = "0" + value;
			
			return value.substring(value.length - 2);
		},
		
		/*----------------------------------------------------------------------*/
		DecodeHTML: function(value){
			value = new String(value + "");

			value = value.replace(/&lt;/gi, "<");

			value = value.replace(/&gt;/gi, ">");

			value = value.replace(/&quot;/gi, "\"");

			value = value.replace(/&amp;/gi, "&");


			return value;
		},
		
		/*----------------------------------------------------------------------*/
		IsNullOrEmpty: function(value){
			return ( !this.IsDefined(value) );
		},
		
		/*----------------------------------------------------------------------*/
		Trim: function(value){
			
			if(this.IsNullOrEmpty(value) || value == "null") return value;
			
			value = value.replace(/^[\t]+|[\t]+$/, "");
			
			return value;
		},

		/*----------------------------------------------------------------------*/
		ToDateTimeString: function(value, format){
			if(this.IsNullOrEmpty(value) || value == "null") return null;

			var dtValue = new Date(value);
			var ret = format;
			ret = ret.replace(/MM/g, this.PadWithZero((dtValue.getMonth() + 1)));
			ret = ret.replace(/M/g, dtValue.getMonth() + 1);
			ret = ret.replace(/dd/g, this.PadWithZero( dtValue.getDate() ) );
			ret = ret.replace(/d/g, dtValue.getDate());
			ret = ret.replace(/yyyy/g, dtValue.getFullYear()); 
			ret = ret.replace(/yy/g, String(dtValue.getFullYear()).substring(2));
			ret = ret.replace(/mm/g, this.PadWithZero( dtValue.getMinutes() ) );
			ret = ret.replace(/m/g, dtValue.getMinutes());
			ret = ret.replace(/hh/g, this.PadWithZero( dtValue.getHours() ) );
			ret = ret.replace(/h/g, dtValue.getHours());
			ret = ret.replace(/ss/g, this.PadWithZero( dtValue.getSeconds() ) );
			ret = ret.replace(/s/g, dtValue.getSeconds());
			ret = ret.replace(/ampm/gi, (dtValue.getHours() > 11 ? "PM" : "AM"));

			return ret;

		},

		/*----------------------------------------------------------------------*/
		StringFormat: function(format, values){
			values = values || [];

			var ret = format;

			for(var x = 0; x < values.length; x++){
				var regex = new RegExp("{[" + x + "]}", "g");
				ret = ret.replace(regex, new String(values[x]));
			}

			return ret;
		},

		/*----------------------------------------------------------------------*/
		Print: function(){
			var html = [];
			for(var x = 0, len = arguments.length; x < len; x++){
				html.push(String(arguments[x]));
			}

			Response.Write(html.join(""));
		},

		/*----------------------------------------------------------------------*/
		PrintLine: function(){
			var html = [];
			for(var x = 0, len = arguments.length; x < len; x++){
				html.push(String(arguments[x]));
			}

			Response.Write(html.join("<br>"));
		},
		
		/*----------------------------------------------------------------------*/
		Req: function(paramName, defaultValue){
			defaultValue = defaultValue || "";

			var param = Request(paramName).count && (Request(paramName) + "")

			return param || defaultValue;
		},

		/*----------------------------------------------------------------------*/
		IsDefined: function(obj){
			return (obj				!== null 
					&& obj			!== "null" 
					&& typeof obj	!== "null" 
					&& typeof obj	!== null 
					&& obj			!== undefined 
					&& obj			!== "undefined" 
					&& typeof obj	!== "undefined" 
					&& typeof obj	!== undefined 
					&& obj			!== "");
		}
	}
 %>
